home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / addicon.lha / AddIcon10 / addicon.s < prev   
Text File  |  1995-12-13  |  7KB  |  359 lines

  1. ;-----------------------------------------------------------------------------
  2. ; AddIcon V1.0
  3. ; Assembled with PhxAss 4.25
  4. ;--------------------------------------------------------------------
  5. ; Address:
  6. ;     Morten Amundsen, Hjuksebø, 3670 NOTODDEN, NORWAY
  7. ; Telephone:
  8. ;     35 95 74 57
  9. ;
  10. ;--------------------------------------------------------------------
  11. ;
  12. ; start: Onsdag, 13. Desember 1995, kl. 14:13
  13. ;   end: Onsdag, 13. Desember 1995, kl. 18:35
  14. ;
  15. ;--------------------------------------------------------------------
  16.  
  17. VERSION    = 36                        ; kick version
  18. WB    = 1                        ; wb startup (0=no)
  19.  
  20. ;--------------------------------------------------------------------
  21.  
  22. NAME:    MACRO
  23.     dc.b    "addicon"
  24.     ENDM
  25.  
  26. VER:    MACRO
  27.     dc.b    "1"
  28.     ENDM
  29.  
  30. REV:    MACRO
  31.     dc.b    "0"
  32.     ENDM
  33.  
  34. DATE:    MACRO
  35.     dc.b    "(13.12.95)"
  36.     ENDM
  37.  
  38. VERSTR:    MACRO
  39.     dc.b    "$VER: "
  40.     NAME
  41.     dc.b    " "
  42.     VER
  43.     dc.b    "."
  44.     REV
  45.     dc.b    " "
  46.     DATE
  47.     dc.b    10,13,0
  48.     ENDM
  49.  
  50. ;--------------------------------------------------------------------
  51.  
  52.     incdir    "include:"
  53.     include    "misc/lvooffsets.i"
  54.     include    "misc/macros.i"
  55.     include    "dos/dosextens.i"
  56.     include    "dos/doshunks.i"
  57.     include    "workbench/workbench.i"
  58.  
  59.     XDEF    _main
  60.     XDEF    _DOSBase
  61.     XDEF    _IconBase
  62.  
  63. _main:    movem.l    d0-d7/a0-a6,-(a7)
  64.  
  65.     sub.l    a1,a1
  66.     EXEC    FindTask
  67.     move.l    d0,a4
  68.  
  69.     moveq    #0,d0
  70.  
  71.     tst.l    pr_CLI(a4)
  72.     bne.s    .CLI
  73.  
  74.     lea    pr_MsgPort(a4),a0
  75.     EXEC    WaitPort
  76.     lea    pr_MsgPort(a4),a0
  77.     EXEC    GetMsg
  78. .CLI:    move.l    d0,_WBMsg
  79.     bne.s    EXIT                    ; shell only
  80.  
  81. ;--------------------------------------------------------------------
  82.  
  83.     OPENLIB    DOSName,VERSION,_DOSBase
  84.     beq.s    EXIT
  85.     OPENLIB    IconName,VERSION,_IconBase
  86.     beq.s    EXIT
  87.  
  88. ;--------------------------------------------------------------------
  89.  
  90.     moveq    #DOS_FIB,d1
  91.     moveq    #0,d2
  92.     CALL    AllocDosObject,_DOSBase
  93.     move.l    d0,_FIB
  94.     bne.s    OK_FIB
  95.  
  96.     CALL    IoErr,_DOSBase
  97.     move.l    d0,d1
  98.     moveq    #0,d2
  99.     CALL    PrintFault,_DOSBase
  100.     bra.s    EXIT
  101.  
  102. OK_FIB:    move.l    #Template,d1
  103.     move.l    #ArgArray,d2
  104.     moveq    #0,d3
  105.     CALL    ReadArgs,_DOSBase        ; process commandline
  106.     move.l    d0,_RDArgs            ; arguments
  107.     bne.s    OK_ARG
  108.  
  109.     CALL    IoErr,_DOSBase
  110.     move.l    d0,d1
  111.     moveq    #0,d2
  112.     CALL    PrintFault,_DOSBase        ; print argument fault
  113.     bra.s    EXIT
  114.  
  115. OK_ARG:    lea    ArgArray,a0
  116.     tst.l    arg_DefTool(a0)
  117.     beq.s    NO_DEF
  118.  
  119.     move.l    arg_DefTool(a0),DefTool
  120.  
  121. NO_DEF:    lea    ArgArray,a0
  122.     move.l    arg_Icon(a0),a0
  123.     CALL    GetDiskObject,_IconBase
  124.     move.l    d0,_ForceIcon            ; icon to add to files
  125.     bne.s    OK_ICN
  126.  
  127.     CALL    IoErr,_DOSBase
  128.     move.l    d0,d6
  129.     cmp.l    #ERROR_OBJECT_NOT_FOUND,d0
  130.     bne.s    .NOT
  131.  
  132.     move.l    #RParTxt,d1
  133.     CALL    PutStr,_DOSBase
  134.  
  135.     lea    ArgArray,a0
  136.     move.l    arg_Icon(a0),d1
  137.     CALL    PutStr,_DOSBase
  138.  
  139.     move.l    #InfoTxt,d1
  140.     CALL    PutStr,_DOSBase
  141.  
  142.     move.l    #LParTxt,d1
  143.     CALL    PutStr,_DOSBase
  144.  
  145. .NOT:    move.l    d6,d1
  146.     moveq    #0,d2
  147.     CALL    PrintFault,_DOSBase
  148.     bra.s    EXIT
  149.  
  150. OK_ICN:    move.l    d0,a0
  151.     move.l    do_ToolTypes(a0),_OldToolTypes
  152.     move.l    do_DefaultTool(a0),_OldDefaultTool
  153.     move.b    do_Type(a0),_OldType
  154.     move.l    do_DrawerData(a0),_OldDrawerData
  155.     move.l    do_ToolWindow(a0),_OldToolsWindow
  156.     move.l    do_StackSize(a0),_OldStackSize
  157.  
  158.     lea    ArgArray,a0
  159.     move.l    arg_Files(a0),a4
  160. MAIN_LOOP:
  161.     move.l    (a4)+,a5
  162.     cmp.l    #NULL,a5
  163.     beq.s    EXIT
  164.  
  165.     move.l    a5,d1
  166.     move.l    #MODE_OLDFILE,d2
  167.     CALL    Open,_DOSBase
  168.     move.l    d0,d6
  169.     bne.s    CHECK_TYPE
  170.  
  171.     CALL    IoErr,_DOSBase
  172.     move.l    d0,d6
  173.  
  174.     move.l    #RParTxt,d1
  175.     CALL    PutStr,_DOSBase
  176.  
  177.     move.l    a5,d1
  178.     CALL    PutStr,_DOSBase
  179.  
  180.     move.l    #LParTxt,d1
  181.     CALL    PutStr,_DOSBase
  182.  
  183.     move.l    d6,d1
  184.     moveq    #0,d2
  185.     CALL    PrintFault,_DOSBase
  186.     bra.s    MAIN_LOOP
  187.  
  188. CHECK_TYPE:
  189.     move.l    d6,d1
  190.     move.l    _FIB,d2
  191.     CALL    ExamineFH,_DOSBase
  192.  
  193.     move.l    _FIB,a0
  194.     move.l    fib_DirEntryType(a0),d0
  195.     bgt.s    SKIP_DIR
  196.  
  197.     move.l    d6,d1                ; read 1st 4 bytes of file
  198.     move.l    #ReadBuffer,d2
  199.     move.l    #4,d3
  200.     CALL    Read,_DOSBase
  201.  
  202.     lea    ReadBuffer,a0
  203.     cmp.l    #HUNK_HEADER,(a0)        ; excutable?
  204.     bne.s    PROJECT_TYPE            ; nope... datafile!
  205.  
  206.     move.l    _ForceIcon,a1
  207.     move.b    #WBTOOL,do_Type(a1)
  208.     move.l    #0,do_DrawerData(a1)
  209.     move.l    #0,do_ToolTypes(a1)
  210.     move.l    #0,do_DefaultTool(a1)
  211.     move.l    #0,do_ToolWindow(a1)
  212.     move.l    #4096,do_StackSize(a1)
  213.     bra.s    PUT_ICON
  214.  
  215. PROJECT_TYPE:
  216.     move.l    _ForceIcon,a1
  217.     move.b    #WBPROJECT,do_Type(a1)
  218.     move.l    #0,do_DrawerData(a1)
  219.     move.l    #0,do_ToolTypes(a1)
  220.     move.l    DefTool,do_DefaultTool(a1)    ; default=MultiView
  221.     move.l    #0,do_ToolWindow(a1)
  222.     move.l    #0,do_StackSize(a1)
  223.  
  224. PUT_ICON:
  225.     move.l    d6,d1
  226.     CALL    Close,_DOSBase
  227.  
  228.     move.l    a5,a0
  229.     move.l    _ForceIcon,a1
  230.     CALL    PutDiskObject,_IconBase
  231.     bra.w    MAIN_LOOP
  232.  
  233. SKIP_DIR:
  234.     move.l    d6,d1
  235.     CALL    Close,_DOSBase
  236.     bra.s    MAIN_LOOP
  237.  
  238. ;--------------------------------------------------------------------
  239.  
  240. EXIT:    bsr.w    FREE_FIB
  241.     bsr.w    FREEARGS
  242.     bsr.w    FREE_FORCEICON
  243.  
  244.     bsr.w    CLOSEDOS
  245.     bsr.w    CLOSEICON
  246.  
  247.     tst.l    _WBMsg
  248.     beq.s    .NOT
  249.  
  250.     EXEC    Forbid
  251.     move.l    _WBMsg,a1
  252.     EXEC    ReplyMsg
  253.     EXEC    Permit
  254. .NOT:    movem.l    (a7)+,d0-d7/a0-a6
  255.     moveq    #0,d0
  256.     rts
  257.  
  258. ;--------------------------------------------------------------------
  259.  
  260. FREE_FIB:
  261.     tst.l    _FIB
  262.     beq.s    .NOT
  263.  
  264.     moveq    #DOS_FIB,d1
  265.     move.l    _FIB,d2
  266.     CALL    FreeDosObject,_DOSBase
  267. .NOT:    rts
  268.  
  269. FREEARGS:
  270.     tst.l    _RDArgs
  271.     beq.s    .NOT
  272.  
  273.     move.l    _RDArgs,d1
  274.     CALL    FreeArgs,_DOSBase
  275. .NOT:    rts
  276.  
  277. FREE_FORCEICON:
  278.     tst.l    _ForceIcon
  279.     beq.s    .NOT
  280.  
  281.     move.l    _ForceIcon,a0
  282.     move.l    _OldToolTypes,do_ToolTypes(a0)
  283.     move.l    _OldDefaultTool,do_DefaultTool(a0)
  284.     move.b    _OldType,do_Type(a0)
  285.     move.l    _OldDrawerData,do_DrawerData(a0)
  286.     move.l    _OldToolsWindow,do_ToolWindow(a0)
  287.     move.l    _OldStackSize,do_StackSize(a0)
  288.  
  289.     CALL    FreeDiskObject,_IconBase
  290. .NOT:    rts
  291.  
  292. ;--------------------------------------------------------------------
  293.  
  294. CLOSEDOS:
  295.     tst.l    _DOSBase
  296.     beq.s    .NOT
  297.  
  298.     CLOSELIB _DOSBase
  299. .NOT:    rts
  300.  
  301. CLOSEICON:
  302.     tst.l    _IconBase
  303.     beq.s    .NOT
  304.  
  305.     CLOSELIB _IconBase
  306. .NOT:    rts
  307.  
  308. ;-----------------------------------------------------------------------------
  309.  
  310.     section    "Data",data
  311.  
  312. _WBMsg:        dc.l    0
  313.  
  314. _DOSBase:    dc.l    0
  315. _IconBase:    dc.l    0
  316. DOSName:    dc.b    "dos.library",0
  317. IconName:    dc.b    "icon.library",0
  318.         VERSTR
  319.         even
  320.  
  321. ;----------------------------------------------------------------------------
  322.  
  323. _FIB:        dc.l    0
  324. _RDArgs:    dc.l    0
  325.  
  326. ; ArgArray offsets
  327.  
  328. arg_Files:    equ    0    ; filelist
  329. arg_Icon:    equ    4    ; icon name to add to files in list
  330. arg_DefTool:    equ    8    ; default tool
  331.  
  332. ArgArray:    dcb.l    3,0
  333.  
  334. Template:    dc.b    "FILES/A/M,ICON/A/K,TOOL/K",0
  335. RParTxt:    dc.b    "(",0
  336. LParTxt:    dc.b    ") ",0
  337. InfoTxt:    dc.b    ".info",0
  338.         even
  339.  
  340. ;--------------------------------------------------------------------
  341.  
  342. DefTool:        dc.l    DefToolTxt
  343. DefToolTxt:        dc.b    "MultiView",0
  344.             even
  345. ReadBuffer:        dc.l    0
  346. _ForceIcon:        dc.l    0        ; icon to add
  347.  
  348. _OldToolTypes:        dc.l    0
  349. _OldDefaultTool:    dc.l    0
  350. _OldDrawerData:        dc.l    0
  351. _OldToolsWindow:    dc.l    0
  352. _OldStackSize:        dc.l    0
  353. _OldType:        dc.b    0
  354.             even
  355.  
  356. NewDrawerData:        dcb.b    DrawerData_SIZEOF,0
  357.  
  358. ;--------------------------------------------------------------------
  359.